#!/bin/bash
# this bash file is only used in docker environment

# author:wangzk@unitechs.com
# date: 2019-05-28

APP_BASE_PATH="$(cd -P "$( dirname "$SOURCE"  )" && pwd)"
# 设置jar绝对路径
APP_JAR=`find *.jar`
JAR_KEYWORDS="$APP_BASE_PATH/$APP_JAR"
# 设置程序名称
APP_NAME=$APP_JAR
# 查找服务进程号
PID=$(ps aux | grep $JAR_KEYWORDS | grep -v grep | awk '{print $2}' )

# 自动查找配置文件
APPLICATION_FILE=""
for file in conf/*; do
    if [[ $file =~ ^conf/application*.yml ]]; then
        APPLICATION_FILE=$file,$APPLICATION_FILE
    elif [[ $file =~ ^conf/application*.properties ]]; then
        APPLICATION_FILE=$file,$APPLICATION_FILE
    elif [[ $file =~ ^conf/bootstrap*.yml ]]; then
        APPLICATION_FILE=$file,$APPLICATION_FILE
    elif [[ $file =~ ^conf/bootstrap*.properties ]]; then
        APPLICATION_FILE=$file,$APPLICATION_FILE
    fi
done
# 删除最后多余的英文逗号
APPLICATION_FILE=${APPLICATION_FILE%,}

JAVA_OPT="$JAVA_OPT -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m"
JAVA_OPT="$JAVA_OPT -XX:-UseLargePages"
java -jar $JAVA_OPTS $JAR_KEYWORDS --spring.config.location=$APPLICATION_FILE